package diona;

import diona.clipboard.ClipboardHelper;
import diona.clipboard.ClipboardItem;
import diona.dao.SharedFileDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: anton
 * Date: 20.03.11 12:28
 */
public class QueueHotKeyListener extends HotKeyListener
{
    private static Logger LOG = LoggerFactory.getLogger(QueueHotKeyListener.class);

    private final Notifier notifier;
    private final SharedFileDao fileDao;

    public QueueHotKeyListener(Notifier notifier, SharedFileDao fileDao)
    {
        this.notifier = notifier;
        this.fileDao = fileDao;
    }

    @Override
    public HotKeyEventType getEventType()
    {
        return HotKeyEventType.QUEUE;
    }

    @Override
    protected void onHotKey()
    {
        try {
            ClipboardItem clipboardItem = ClipboardHelper.getClipboardItem();
            if (clipboardItem != null) {
                clipboardItem.save(fileDao);
                notifier.showMessage(clipboardItem.getDescription() + " added to queue.");

            } else {
                LOG.debug("ClipboardItem is null");
            }
        } catch (Exception e) {
            LOG.error("Error while hot key processing", e);
        }
    }
}
